<!--
@name:tabProjectConfiguration
@author:Zhenglei
@date:15:19
@description:tabProjectConfiguration
@update:2022/8/1515:19
-->
<template>
  <div class="pd-20">
    <el-button type="primary"
               @click="handleOption('add',null)">新 增
    </el-button>
    <element-table
      class="mt-20"
      :columns="columns"
      :data="tableData"
      v-loading="loading"
      pager
      :pageTotal="pageTotal"
      :pageIndex="pageIndex"
      :pageSize="pageSize"
      @handleChangePage="handleChangePage">

      <template v-slot:option="{row,index}">
        <el-button type="primary"
                   @click="handleOption('edit', row)">编辑
        </el-button>
        <el-button type="warning"
                   @click="handleOption('point', row)">指征配置
        </el-button>
        <el-button type="danger"
                   @click="handleOption('del', row)">删除
        </el-button>
      </template>
    </element-table>

    <dialog-config v-if="showDialog" :visible.sync="showDialog" :dataObj="dataObj"/>
    <dialog-point v-if="showPointDialog" :visible.sync="showPointDialog" :dataObj="dataObj"/>
  </div>
</template>

<script>
import ElementTable from "../../../../base/ElementTable";
import dialogProjectConfiguration from "./dialogProjectConfiguration";
import dialogPointList from "./dialogPointList";

export default {
  name: "tabProjectConfiguration",
  data() {
    return {
      formModel: {
        age: [],
        sex: '',
        status: ''
      },
      showDialog: false,
      showPointDialog: false,
      dataObj: {},
      loading: false,
      tableData: [],
      pageTotal: 0,
      pageIndex: 1,
      pageSize: 20,
      columns: [
        {
          label: '常测项名称',
          prop: 'name',
          align: 'center',
        }, {
          label: '主题/项目',
          prop: 'dolThemeName',
          align: 'center',
        }, {
          label: '排序',
          prop: 'sort',
          align: 'center',
        }, {
          label: '操作',
          prop: 'option',
          align: 'center',
          isSlot: true,
          width:360
        }
      ]

    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleOption(op, row) {
      switch (op) {
        case 'add':
          this.dataObj = {}
          this.showDialog = true
          break;
        case 'edit':
          this.dataObj = row
          this.showDialog = true
          break
        case 'point':
          this.dataObj = row
          this.$set(this.dataObj,'themeId',row.id)
          this.showPointDialog = true
          break
        case 'del':
          this.$confirm('是否要确认?', '提示', {
            type: 'warning'
          }).then(() => {
            this.post(this.api.healthMap.delDolConstant, {
              id: row.id
            }).then((res) => {
              if (res.data.code === '200') {
                this.$message.success('删除成功!');
                this.getList()
              }
            })
          })
          break

      }

    },

    getList() {
      this.loading = true
      this.post(this.api.healthMap.getDolConstantList,{
        pageIndex: this.pageIndex - 1,
        pageSize: this.pageSize,
      }).then((res) => {
        this.loading = false
        if (res.data.code === '200') {
          this.tableData = res.data.object
          this.pageTotal = res.data.totalNum
        }
      })
    },
    // 分页
    handleChangePage(page) {
      this.pageIndex = page;
      this.getList();
    },

  },
  components: {
    'element-table': ElementTable,
    'dialog-config': dialogProjectConfiguration,
    'dialog-point': dialogPointList,
  }
}
</script>

<style scoped>

</style>
